﻿using System.Configuration;
using LiveNet.Photos;
using LiveNet.Contacts;

namespace LiveNet.Configuration
{
    public sealed class ConfigurationSectionHandler : ConfigurationSection
    {
        private static ConfigurationSectionHandler _configurationSection;

        /// <summary>
        /// Gets this instance.
        /// </summary>
        /// <returns></returns>
        public static ConfigurationSectionHandler Get()
        {
            if (_configurationSection == null)
            {
                _configurationSection = (ConfigurationSectionHandler)ConfigurationManager.GetSection("liveNet");

                if (_configurationSection == null)
                {
                    _configurationSection = new ConfigurationSectionHandler();
                }
            }

            return _configurationSection;
        }

        /// <summary>
        /// Gets or sets the name of the application.
        /// </summary>
        /// <value>The name of the application.</value>
        [ConfigurationProperty("applicationName", IsRequired = false, DefaultValue = "LiveNet Based Application")]
        public string ApplicationName
        {
            get
            {
                return (string)this["applicationName"];
            }
            set { this["applicationName"] = value; }
        }

        /// <summary>
        /// Gets or sets the type of the authentication obtainer.
        /// </summary>
        /// <value>The type of the authentication obtainer.</value>
        [ConfigurationProperty("authenticationObtainerType", IsRequired = false)]
        public string AuthenticationObtainerType
        {
            get { return (string)this["authenticationObtainerType"]; }
            set { this["authenticationObtainerType"] = value; }
        }

        /// <summary>
        /// Gets or sets the spaces authorization.
        /// </summary>
        /// <value>The spaces authorization.</value>
        [ConfigurationProperty("spacesAuthorization")]
        [ConfigurationValidator(typeof(AuthorizationConfigElementValidator<SpacesPermission>))]
        public AuthorizationConfigElement<SpacesPermission> SpacesAuthorization
        {
            get { return (AuthorizationConfigElement<SpacesPermission>)this["spacesAuthorization"]; }
            set { this["spacesAuthorization"] = value; }
        }

        /// <summary>
        /// Gets or sets the contacts authorization.
        /// </summary>
        /// <value>The contacts authorization.</value>
        [ConfigurationProperty("contactsAuthorization")]
        [ConfigurationValidator(typeof(AuthorizationConfigElementValidator<ContactsPermission>))]
        public AuthorizationConfigElement<ContactsPermission> ContactsAuthorization
        {
            get { return (AuthorizationConfigElement<ContactsPermission>)this["contactsAuthorization"]; }
            set { this["contactsAuthorization"] = value; }
        }
    }
}
